package com.seawaterbt.ssm.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.seawaterbt.ssm.entity.*;
import com.seawaterbt.ssm.service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

@Service
public class ZDatRoomTemp {
    DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    @Autowired
    CzDatRoomtempService datRoomtempService;

    @Autowired
    CzBasHouseholdService basHouseholdService;
    @Autowired ZDatRoomTempService zDatRoomTempService;

    //新增任丘典型测温
    public void sendData() {
        QueryWrapper<CzDatRoomtemp> queryWrapper = new QueryWrapper<>();
        queryWrapper.likeRight("household_code", 130902008).or().likeRight("household_code", 130903007).or().likeRight("household_code",130982020);
        List<CzDatRoomtemp> datRoomtemp = datRoomtempService.list(queryWrapper);
        Date date = new Date();
        for (CzDatRoomtemp data : datRoomtemp) {
            BasHousehold one = basHouseholdService.listOne(data.getHouseholdCode());
            if (one != null && one.getRoomCodeProvince() != null && !one.getRoomCodeProvince().equals("")) {
                QueryWrapper wrapper = new QueryWrapper();
                wrapper.eq("HouseHoldID", one.getRoomCodeProvince());
                wrapper.eq("GetTime", data.getGetTime());
                ShengDatRoomTemp byCodeTime = zDatRoomTempService.getByCodeTime(wrapper);
                if (byCodeTime == null) {
                    ShengDatRoomTemp datData = new ShengDatRoomTemp();
                    datData.setHouseHoldId(one.getRoomCodeProvince());
                    datData.setAddTime(date);
                    datData.setGetTime(data.getGetTime());
                    datData.setRoomTemp(Double.valueOf(data.getRoomTemp()));
                    zDatRoomTempService.save(datData);
                }
            }
        }
        System.out.println("完成同步典型测温到中间库 " + df.format(new Date()));
    }
}
